package com.bingxue.edu.parent.controller;

import com.bingxue.edu.framework.common.util.ValidationUtils;
import com.bingxue.edu.management.education.service.StudentService;
import com.bingxue.edu.parent.util.ParentAuthUtil;
import org.springframework.beans.factory.annotation.Autowired;

import static com.bingxue.edu.management.education.model.entity.table.StudentTableDef.STUDENT;

/**
 * @author panbo
 * @since 2024/12/16
 */
public abstract class ParentBaseController {

    @Autowired
    private StudentService studentService;


    public void checkStudentRelation(String studentId) {
        ValidationUtils.throwIfNull(studentId, "学生id不能为空");
        String currentParentId = ParentAuthUtil.getCurrentParentId();
        boolean exists = studentService.queryChain()
                .where(STUDENT.ID.eq(studentId))
                    .and(STUDENT.PARENT_ID.eq(currentParentId))
                .exists();
        ValidationUtils.throwIf(!exists, "学生信息不存在");
    }
}
